/*
Lab08-T01 (Fully commented code)
Jimmy Manone
10/23/2014

*/

#include	<stdint.h>
#include	<stdbool.h>
#include	"inc/hw_types.h"
#include	"inc/hw_memmap.h"
#include	"driverlib/sysctl.h"
#include	"driverlib/pin_map.h"
#include	"driverlib/debug.h"
#include	"driverlib/gpio.h"
#include	"driverlib/flash.h" //Add support for flash APIs
#include	"driverlib/eeprom.h" //EEPROM API support


int	main(void)
{

	uint32_t	pui32Data[2]; //Buffers for read/write data
	uint32_t	pui32Read[2];
	pui32Data[0]	=	0x12345678;
	pui32Data[1]	=	0x56789abc;



	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,	GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,	0x00);
	SysCtlDelay(20000000);

	FlashErase(0x10000); //Erases block of flash (map)
	FlashProgram(pui32Data,	0x10000,	sizeof(pui32Data)); //Program data array
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,	0x02); //LED -success
	SysCtlDelay(20000000); //Delay for approximately 2 seconds

	SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); //Activate EEPROM peripheral
	EEPROMInit(); //Power failure recovery
	EEPROMMassErase(); //Erase entire EEPROM
	EEPROMRead(pui32Read,	0x0,	sizeof(pui32Read)); //Read erased values into pulRead
	EEPROMProgram(pui32Data,	0x0,	sizeof(pui32Data)); //program array into beginning of EEPROM
	EEPROMRead(pui32Read,	0x0,	sizeof(pui32Read)); //Read data into pulRead array
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,	0x04); //Red LED off-Blue LED on

	while(1)
	{
	}
}